package github.fafaovo;

import github.fafaovo.common.config.exampleconfig;
import github.fafaovo.common.event.CommandEvents;
import github.fafaovo.common.event.CreateFluidEvent;
import github.fafaovo.common.event.JoinWorldEvent;
import github.fafaovo.common.guiblock.GuiBlockInit;
import github.fafaovo.common.guiblock.Screen.ExampleBurnMachineScreen;
import github.fafaovo.common.guiblock.Screen.ExampleInitialScreen;
import github.fafaovo.core.init.ContainerInit;
import github.fafaovo.core.init.EnchantmentInit;
import github.fafaovo.core.init.ItemInit;
import github.fafaovo.network.NetworkRegistryHandler;
import net.minecraft.client.gui.ScreenManager;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.EventPriority;
import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.config.ModConfig;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.server.permission.DefaultPermissionLevel;
import net.minecraftforge.server.permission.PermissionAPI;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

// The value here should match an entry in the META-INF/mods.toml file
@Mod("fafaovo")
public class deepcapacity {

    public static final Logger LOGGER = LogManager.getLogger();
    public static final String MOD_ID = "deepcapacity";
    // Directly reference a log4j logger.

    public deepcapacity() {
        MinecraftForge.EVENT_BUS.register(this);

        // Register ourselves for server and other game events we are interested in
        MinecraftForge.EVENT_BUS.register(this);

        //权限注册
        PermissionAPI.registerNode("a.random.permission.key", DefaultPermissionLevel.OP, "My first permission");

        ItemInit.ITEMS.register(FMLJavaModLoadingContext.get().getModEventBus());

        GuiBlockInit.BLOCKS.register(FMLJavaModLoadingContext.get().getModEventBus());
        GuiBlockInit.ITEMS.register(FMLJavaModLoadingContext.get().getModEventBus());

        //注册网络发包
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::onCommonSetUp);


        MinecraftForge.EVENT_BUS.addListener(
                EventPriority.HIGH,
                JoinWorldEvent::onJoinWorld);

        MinecraftForge.EVENT_BUS.addListener(
                EventPriority.HIGH,
                CommandEvents::commandRegister);

        MinecraftForge.EVENT_BUS.addListener(
                EventPriority.HIGH,
                CreateFluidEvent::onFluidPlaceBlockEvent);




        //注册config
        ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, exampleconfig.SPEC,"deep-capacity-common.toml");

        //界面注册
        ContainerInit.CONTAINERS_TYPE.register(FMLJavaModLoadingContext.get().getModEventBus());

        //机器注册
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::onClientSetup);

        //附魔注册
        EnchantmentInit.ENCHANTS.register(FMLJavaModLoadingContext.get().getModEventBus());


    }

    public void onCommonSetUp(FMLCommonSetupEvent event)
    {
        NetworkRegistryHandler.registerMessage();
        //注册完之后需要同步一下数据 玩家加入的时候 玩家死亡
    }

    public void onClientSetup(FMLCommonSetupEvent event)
    {
        //绑定注册GUI 一个是实体界面 一个是渲染贴图
        ScreenManager.registerFactory(ContainerInit.BURN_CONTAINERS.get(), ExampleBurnMachineScreen::new);
        ScreenManager.registerFactory(ContainerInit.INITIAL_CONTAINERS.get(), ExampleInitialScreen::new);


    }
}
